package labmanager.services;

import java.util.ArrayList;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import labmanager.business.LabManagerReservation;
import labmanager.business.LabManagerTypeReservation;
import labmanager.business.LabManagerUser;

import org.apache.log4j.Logger;

import dto.ResponseDTO;

@WebService()
public class WSLabManager {

	private static Logger logger = Logger.getLogger(WSLabManager.class);

	public WSLabManager() {
	}

	/**
	 * Metodo que permite realizar el ingreso a la aplicacion.
	 * 
	 * @param user_name
	 * @param password
	 * @return
	 */
	@WebMethod(operationName = "loginUser")
	public ResponseDTO loginUser(
			@WebParam(name = "user_name") String user_name,
			@WebParam(name = "password") String password) {

		LabManagerUser labmanager = new LabManagerUser();
		return labmanager.loginUser(user_name, password);
	}

	/**
	 * Metodo que registra un usuario en base de datos
	 * 
	 * @param code
	 * @param name
	 * @param lastName
	 * @param userName
	 * @param password
	 * @param state
	 * @param profileId
	 * @return
	 */
	@WebMethod(operationName = "createUser")
	public ResponseDTO createUser(@WebParam(name = "code") int code,
			@WebParam(name = "name") String name,
			@WebParam(name = "lastName") String lastName,
			@WebParam(name = "userName") String userName,
			@WebParam(name = "password") String password,
			@WebParam(name = "state") int state,
			@WebParam(name = "profileId") int profileId) {

		LabManagerUser labmanager = new LabManagerUser();
		return labmanager.createUser(code, name, lastName, userName, password,
				state, profileId);
	}

	/**
	 * Metodo que lista los usuarios
	 * 
	 * @param where
	 * @return
	 */
	@WebMethod(operationName = "listUsers")
	public ArrayList<String> listUsers(@WebParam(name = "where") String where) {

		LabManagerUser labmanager = new LabManagerUser();
		return labmanager.listUsers(where);
	}

	/**
	 * Metodo que actuliza un usuario en base de datos
	 * 
	 * @param code
	 * @param name
	 * @param lastName
	 * @param userName
	 * @param password
	 * @param state
	 * @param profileId
	 * @return
	 */
	@WebMethod(operationName = "updateUser")
	public ResponseDTO updateUser(@WebParam(name = "code") int code,
			@WebParam(name = "name") String name,
			@WebParam(name = "lastName") String lastName,
			@WebParam(name = "userName") String userName,
			@WebParam(name = "password") String password,
			@WebParam(name = "state") int state,
			@WebParam(name = "profileId") int profileId) {

		LabManagerUser labmanager = new LabManagerUser();
		return labmanager.updateUser(code, name, lastName, userName, password,
				state, profileId);
	}

	/**
	 * Metodo que lista los tipos de reservas
	 * 
	 * @param where
	 * @return
	 */
	@WebMethod(operationName = "listTypeReservation")
	public ArrayList<String> listTypeReservation(
			@WebParam(name = "where") String where) {

		LabManagerTypeReservation labmanager = new LabManagerTypeReservation();
		return labmanager.listTypeReservation(where);
	}

	/**
	 * Metodo que registra una reserva en base de datos
	 * 
	 * @param dateReservation
	 * @param typeReservation
	 * @param timeReservation
	 * @param userId
	 * @return
	 */
	@WebMethod(operationName = "createReservation")
	public ResponseDTO createReservation(
			@WebParam(name = "dateReservation") String dateReservation,
			@WebParam(name = "typeReservation") int typeReservation,
			@WebParam(name = "timeReservation") int timeReservation,
			@WebParam(name = "state") String state,
			@WebParam(name = "userId") int userId) {

		LabManagerReservation labmanager = new LabManagerReservation();
		return labmanager.createReservation(dateReservation, typeReservation,
				timeReservation, state, userId);
	}
	
	/**
	 * Metodo que actualiza una reserva en base de datos
	 * 
	 * @param code
	 * @param name
	 * @param lastName
	 * @param userName
	 * @param password
	 * @param state
	 * @param profileId
	 * @return
	 */
	@WebMethod(operationName = "updateReservation")
	public ResponseDTO updateReservation(@WebParam(name = "id") int id,
			@WebParam(name = "dateReservation") String dateReservation,
			@WebParam(name = "typeReservation") int typeReservation,
			@WebParam(name = "timeReservation") int timeReservation,
			@WebParam(name = "state") String state) {

		LabManagerReservation labmanager = new LabManagerReservation();
		return labmanager.updateReservation(id, dateReservation, typeReservation,
				timeReservation, state);
	}

}
